package com.ruoyi.web.controller.workJob;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.worker.domain.ProfessionRank;
import com.ruoyi.worker.domain.SeniorityAwardSetting;
import com.ruoyi.worker.service.ProfessionRankService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author whj
 */
@RestController
@RequestMapping("/professionRank")
public class ProfessionRankController extends BaseController {
    private static final Logger LOGGER = LoggerFactory.getLogger(ProfessionRankController.class);
    @Autowired
    private ProfessionRankService ProfessionRankService;

    @GetMapping("/list")
    public TableDataInfo getProfessionRankListInfo(ProfessionRank professionRank) {
        startPage();
        List<ProfessionRank> companyList = ProfessionRankService.getProfessionRankListInfo(professionRank);
        return getDataTable(companyList);
    }

    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(ProfessionRank professionRank) {
        if(professionRank.getRankName() != null){
            return toAjax(ProfessionRankService.add(professionRank));
        }
        return AjaxResult.error("数据缺失，不能修改职级信息");
    }

    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(ProfessionRank professionRank) {
        if(professionRank.getId() >0){
            return toAjax(ProfessionRankService.edit(professionRank));
        }
        return AjaxResult.error("数据缺失，不能修改职级信息");
    }

    /**
     * 删除
     */
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ProfessionRankService.remove(ids));
    }

    /**
     * 工龄设置查询
     */
    @PostMapping("/getSeniorityAwardSetting")
    public SeniorityAwardSetting getSeniorityAwardSettingListInfo(SeniorityAwardSetting seniorityAwardSetting) {
        return ProfessionRankService.getSeniorityAwardSettingListInfo(seniorityAwardSetting);
    }

    /**
     * 工龄设置提交
     */
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PostMapping("/seniorityAdd")
    public AjaxResult updateSeniorityAwardSetting(SeniorityAwardSetting seniorityAwardSetting) {
        logger.debug("seniorityAwardSetting="+seniorityAwardSetting.getSeniorityAward());
        if(seniorityAwardSetting.getHiredate() != null){
            ProfessionRankService.updateSeniorityAwardSetting(seniorityAwardSetting);
            return AjaxResult.success();
        }else{
            return AjaxResult.error("数据缺失，不能修改龄设置");
        }
    }
}
